import React from 'react'
import store from '../../store/store' //引入store

import {
  incrementAction,  //累加
  decrementAction,  //累减
  waitincrementAction, //异步累加
} from '../../store/actions/countActions'  //引入action



export default function Count() {

  const { count } = store.getState()  //拿到store的值

  //累加
  const incrementHandle = () => {
    store.dispatch(incrementAction(1))
  }

  //累减
  const decreamentHandle = () => {
    store.dispatch(decrementAction(1))
  }

  //基数加
  const ifOddDecrementHandle = () => {
    if (count % 2 !== 0) {
      store.dispatch(incrementAction(1))
    }

  }

  //异步累加
  const waitDecrementHandle = () => {
    store.dispatch(waitincrementAction(1))
  }


  return (
    <div>
      <h1>我是Count组件 我的值是{count}</h1>
      <div>
        <button onClick={incrementHandle}>累加</button>
        <button onClick={decreamentHandle}>累减</button>
        <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
        <button onClick={waitDecrementHandle}>等2s再加1</button>
      </div>

    </div>
  )
}
